var status = "investing";
var pageNo =0;
var totalPage;

$(function(){
	/* 初始加载数据   */
	init();
	
	/* 分页页码  */
	if(totalPage == 0){
		$("#page").html('<tr><td colspan="9">暂无记录</td></tr>');
	}else{
		$("#page").Page({
			totalPages : totalPage,//分页总数
			liNums : 7,//分页的数字按钮数(建议取奇数)
			activeClass : 'activP', //active 类样式定义
		    hasFirstPage: true,//whether has first button
		    hasLastPage: true,//whether has last button
		    hasPrv: true,//whether has prev button
		    hasNext: true,//whether has next button
			callBack : function(page){
				pageNo = page;
				init();
			}
		});
	}
});

function init(){
	$.ajax({
		url:g_requestContextPath + "/user/myInvestLog",
		type:"post",
		async:false,
		dataType:"json",
		data:{"status":status,"pageNo":pageNo},
		success:function(result){
			var units = {"day":"天","month":"月","week":"周","year":"年"};
			var repayTypes = {"averageTotal":"等额本息","payInterestPayCapital":"付息还本","payAllTheEnd":"到期还本付息"};
			totalPage = Math.ceil(result.totalRow / 5);
			var data = result.list;
			var investsHtml = '';
			for (var i = 0; i < data.length; i++) {
				investsHtml += '<tr>';
				investsHtml += '<td><div class="data">'+data[i].investDate.substring(0,10)+'</div>';
				investsHtml += '<div class="time">'+data[i].investDate.substring(11,16)+'</div>';
				investsHtml += '</td>';
				investsHtml += '<td>'+data[i].proTitle+'</td>';
				investsHtml += '<td>'+data[i].process+'%</td>';
				investsHtml += '<td>'+thousandBitSeparator(parseInt(data[i].amount/100))+'</td>';
				investsHtml += '<td>'+data[i].rate+'%</td>';
				investsHtml += '<td>'+data[i].cycle+''+units[data[i].unit]+'</td>';
				investsHtml += '<td>'+repayTypes[data[i].repayType]+'</td>';
				investsHtml += '<td><a href = "'+g_requestContextPath+'/account/paymentsDetial/'+data[i].pid+'/'+data[i].dealCode+'">详情</a></td>';
				investsHtml += '<td><a target="_blank" href="'+g_requestContextPath+'/p/pContract/'+data[i].dealCode+'"><img title="查看合同" src="'+g_requestContextPath+'/images/account/contract.jpg" alt="合同"></a></td>';
				investsHtml += '</tr>';
			}
			$("#investList").html(investsHtml);
		}
	});
	
}

$("#optionsUl a").click(function(){
	$(this).parent().addClass("active").siblings().removeClass("active");
	pageNo = 0;
	status = $(this).attr("data-id");
	init();
	if(totalPage == 0){
		$("#page").html('<tr><td colspan="9">暂无记录</td></tr>');
	}else{
		$("#page").Page({
			totalPages : totalPage,//分页总数
			liNums : 7,//分页的数字按钮数(建议取奇数)
			activeClass : 'activP', //active 类样式定义
		    hasFirstPage: true,//whether has first button
		    hasLastPage: true,//whether has last button
		    hasPrv: true,//whether has prev button
		    hasNext: true,//whether has next button
			callBack : function(page){
				pageNo = page;
				init();
			}
		});
	}
});